package org.example;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "RequestForwardServlet", value = "/forward")
public class Servlet05 extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 设置响应体内容类型
        response.setContentType("text/html; charset=utf-8");
        // 设置请求对象属性
        request.setAttribute("message","转发成功！");
        // 获取请求派发器对象(参数是请求转发的Servlet的url)
        RequestDispatcher dispatcher = request.getRequestDispatcher("/result");
        // 请求转发给url为‘/result’的Servlet
        dispatcher.forward(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request,response);
    }
}


